package com.lmx.tour_management_system.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lmx.tour_management_system.mapper.AttractionsMapper;
import com.lmx.tour_management_system.mapper.CommentsMapper;
import com.lmx.tour_management_system.pojo.Attraction;
import com.lmx.tour_management_system.pojo.Comments;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

@Controller
//控制页面跳转Controller
public class RouterController {

    @Resource
    AttractionsMapper attractionsMapper;

    @Resource
    CommentsMapper commentsMapper;

    @RequestMapping("/toIndex")
    public String toIndex(Model model){
        return "redirect:/";
    }

    @RequestMapping("/toInformations")
    public String toInformations(){
        return "informations";
    }

    @RequestMapping("/toQuery")
    public String toQuery(Model model){

        ArrayList<String> names = new ArrayList<>();
        List<Attraction> attractions = attractionsMapper.selectList(null);

        for(Attraction attraction:attractions){
            names.add(attraction.getAttractionCity());
        };

        HashSet hashSet = new HashSet(names);

        model.addAttribute("names",hashSet);
        return "query";
    }

    @RequestMapping("/toScenery")
    public String toScenery(){
        return "scenery";
    }
    @RequestMapping("/toAbout")
    public String toAbout(){
        return "about";
    }

    @RequestMapping("/toLogin")
    public String toLogin(){
        return "login";
    }

    @RequestMapping("/toSceneryInfo/{id}")
    public String toSceneryInfo(@PathVariable("id") int id,Model model){
        Attraction attraction = attractionsMapper.selectOne(new QueryWrapper<Attraction>().eq("attraction_id", id));
        model.addAttribute("attraction",attraction);
        return "scenery_info";
    }

    @RequestMapping("/toComments")
    public String toComments(Model model){
        List<Map<String, String>> comments = commentsMapper.queryAllComments();
        model.addAttribute("comments",comments);
        return "comments";
    }



}
